//
//  SKBaseViewController.m
//  SouthKoreaDoorLock
//
//  Created by Umeinfo on 2018/1/15.
//  Copyright © 2018年 andy90s. All rights reserved.
//

#import "SKBaseViewController.h"
#import "SKBaseNavigationController.h"

@interface SKBaseViewController ()

// iconview
@property (nonatomic, strong) UIView *iconView;

@end

@implementation SKBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.00];
    [self setupNavigationBar];
}

- (void)setupNavigationBar {
    [self.view addSubview:self.navigationBar];
    SKBaseNavigationController *baseNav = (SKBaseNavigationController *)self.navigationController;
    if ([self.navigationController.viewControllers[0] isKindOfClass:[self class]]) {
        [self setupNavIconViews];
    }
    weakify(self);
    if ([baseNav isKindOfClass:[SKBaseNavigationController class]]) {
        baseNav.block = ^{
            strongify(self);
            [self rightNavItemClick];
        };
    }
//    baseNav.block = ^{
//        strongify(self);
//        [self rightNavItemClick];
//    };
}

- (void)setupNavIconViews {
    [self.navigationBar addSubview:self.iconView];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.navigationBar);
        make.height.offset(44);
        make.bottom.equalTo(self.navigationBar);
    }];  
}

#pragma mark - Action
// for childviewController.
- (void)rightNavItemClick {
    
}

#pragma mark - Access

- (void)setTitle:(NSString *)title {
    
    self.navItem.title = title;
}

#pragma mark - lazy

- (SKNavigationBar *)navigationBar {
    if (!_navigationBar) {
        if (k_iPhoneX) {
            _navigationBar = [[SKNavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 88)];
        } else {
            _navigationBar = [[SKNavigationBar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
        }
        
        _navigationBar.tintColor = [UIColor whiteColor];
        _navigationBar.barTintColor = [UIColor colorWithRed:0.12 green:0.12 blue:0.12 alpha:1.00];
        _navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
        _navigationBar.items = @[self.navItem];
    }
    return _navigationBar;
}

- (UINavigationItem *)navItem {
    if (!_navItem) {
        _navItem = [UINavigationItem new];
        
    }
    return _navItem;
}

- (UIView *)iconView {
    if (!_iconView) {
        _iconView = [UIView new];
        UIImageView *icon = [UIImageView new];
        icon.image = [UIImage imageNamed:@"ic_launcher"];
        [self.iconView addSubview:icon];
        
        UILabel *titleLab = [UILabel new];
        titleLab.textColor = [UIColor whiteColor];
        titleLab.text = SKLANGUAGE(@"ROOT_KEES_DOORLOCK");
        [self.iconView addSubview:titleLab];
        [icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView).offset(20);
            make.width.height.offset(35);
            make.centerY.equalTo(self.iconView);
        }];
        
        
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.iconView);
            make.left.equalTo(icon.mas_right).offset(10);
        }];
       
    }
    return _iconView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
